package org.chengn.level_middle.context1599;

/**
 * @Title: Context1599
 * @Author ChengN
 * @Package org.chengn.level_middle.context1599
 * @Date 2024/1/1 1:34
 * @description: 经营摩天轮的最大利润
 */
public class Context1599 {
    public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {
        int len = customers.length;
        int nowWait = 0;
        int res = 0, time = 0;
        int maxRes = 0, maxTime = -1;
        int i = 0;
        while (i < len || nowWait > 0) {
            time++;
            if (i < len) {
                nowWait += customers[i++];
            }
            int canBoard = Math.min(4, nowWait);
            res += canBoard * boardingCost - runningCost;
            nowWait -= canBoard;
            if (res > maxRes) {
                maxRes = res;
                maxTime = time;

            }
        }
        return maxTime;
    }
}
